home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: tycope@aol.com (Tycope)
- Newsgroups: comp.lang.c
- Subject: Re: Simple Loop answer
- Date: 1 Mar 1996 03:49:51 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4h6dnf$fts@newsbf02.news.aol.com>
- Reply-To: tycope@aol.com (Tycope)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- Here is what I finally came up with.........
-
-
- #include <stdio.h>
- #define MAX 1000
-
- long int i, j, k, l;
- long int count = 0;
- long int compares = 0;
-
- int
- main (void)
- {
-
-
- for (i = 1; i <= MAX - 3; i++)
- for (j = i + 1; j <= MAX - 2; j++)
- for (k = j + 1; k <= MAX - 1; k++)
- {
- l = i + j + k;
- compares++;
-
- if (((0 < i) && (i < j)) && ((j < k) && (k < l)))
- if (l <= MAX)
- { count++;
- if (compares % 1000000 == 0)
- {
- printf("%ld(i) + %ld(j) + %ld(k) = %ld(l)\n", i,
- j, k, l);
-
- }
- }
- }
-
- printf("The number of triples is: %ld\n\n", count);
- printf("The number of compares is: %ld\n", compares);
-
- return (0);
- }
-